home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: System Software / Apple_Developer_Group_April_1996_System_Software.iso / What's New? / Sample Code / Snippets Update 1 / CustomGet unresolved alias / CustomGet unresolved alias.c < prev    next >
Encoding:
Text File  |  1996-01-30  |  2.6 KB  |  109 lines  |  [TEXT/CWIE]

  1.     //
  2.     //    This sample demonstrates how to let the user choose an alias file
  3.     //    from an "open" dialog. The basic idea is to intercept the pseudo-
  4.     //    item 'sfHookOpenAlias' in a CustomGetFile hook function and transform
  5.     //    it into 'getOpen'. This causes the dialog to behave as if the user
  6.     //    had clicked the open button. Also, we intercept the item number of
  7.     //    a check box we have added to the dialog item template in order to
  8.     //    allow the user to choose whether to resolve aliases. Finally,
  9.     //    when CustomGetFile returns, we call DebugStr to let the user (you,
  10.     //    the programmer, not end users -- they'll just see a crash) know
  11.     //    what happened.
  12.     //
  13.     //    Complaints and kudos to:
  14.     //
  15.     //        Pete Gontier
  16.     //        Apple Macintosh Developer Technical Support
  17.     //        <gurgle@apple.com>
  18.     //
  19.     //    Change history
  20.     //
  21.     //        01/25/95    initial version
  22.     //        01/30/95    use AppendDITL instead of copy of System resources
  23.     //
  24.     //
  25.  
  26. #define OLDROUTINELOCATIONS        0
  27. #define OLDROUTINENAMES            0
  28. #define SystemSevenOrLater        1
  29.  
  30. #ifndef __FONTS__
  31. #    include <Fonts.h>
  32. #endif
  33.  
  34. #ifndef __DIALOGS__
  35. #    include <Dialogs.h>
  36. #endif
  37.  
  38. #ifndef __STANDARDFILE__
  39. #    include <StandardFile.h>
  40. #endif
  41.  
  42. #ifndef __RESOURCES__
  43. #    include <Resources.h>
  44. #endif
  45.  
  46. static pascal OSErr InitMac (void)
  47. {
  48.     MaxApplZone ( );
  49.     InitGraf (&(qd.thePort));
  50.     InitFonts ( );
  51.     InitWindows ( );
  52.     InitMenus ( );
  53.     TEInit ( );
  54.     InitDialogs (nil);
  55.  
  56.     return noErr;
  57. }
  58.  
  59. static short gItemIndex_CustomGetCheckBox;
  60. static const short kResID_CustomGetCheckBox = 128;
  61.  
  62. static pascal short DlgHookYDProc (short item, DialogRef dRef, void *)
  63. {
  64.     if (item == sfHookFirstCall)
  65.     {
  66.         Handle checkBoxDitlH = GetResource ('DITL',kResID_CustomGetCheckBox);
  67.         if (!ResError ( ) && checkBoxDitlH)
  68.         {
  69.             DetachResource (checkBoxDitlH);
  70.             if (ResError ( ))
  71.                 ReleaseResource (checkBoxDitlH);
  72.             else
  73.             {
  74.                 gItemIndex_CustomGetCheckBox = 1 + CountDITL (dRef);
  75.                 AppendDITL (dRef,checkBoxDitlH,appendDITLBottom);
  76.                 DisposeHandle (checkBoxDitlH);
  77.             }
  78.         }
  79.     }
  80.     else if (item == gItemIndex_CustomGetCheckBox || item == sfHookOpenAlias)
  81.     {
  82.  
  83.         short iType; Rect iRect; Handle iHandle; Boolean iValue;
  84.         GetDialogItem (dRef,gItemIndex_CustomGetCheckBox,&iType,&iHandle,&iRect);
  85.         iValue = GetControlValue ((ControlRef) iHandle);
  86.         if (item != sfHookOpenAlias)
  87.             SetControlValue ((ControlRef) iHandle, !iValue);
  88.         else if (!iValue)
  89.             item = getOpen;
  90.     }
  91.  
  92.     return item;
  93. }
  94.  
  95. void main (void)
  96. {
  97.     if (!InitMac ( ))
  98.     {
  99.         StandardFileReply sfr;
  100.         Point sfWhere = {-1,-1};
  101.         CustomGetFile (nil,-1,nil,&sfr,sfGetDialogID,sfWhere,DlgHookYDProc,nil,nil,nil,nil);
  102.  
  103.         if (sfr.sfGood)
  104.             DebugStr (sfr.sfFile.name);
  105.         else
  106.             DebugStr ("\pAs the world's worst singer would say: 'No reply at all.'");
  107.     }
  108. }
  109.